﻿using UnityEngine;
using System.Collections;

public class Character_Health : MonoBehaviour {
	
	public int healthMax;
	//the character's maximum health.
	
	int health;

	Character_Player character;
	
	

	// Use this for initialization
	void Start () {
		health=healthMax;
		
		character=GetComponent<Character_Player>();
	}
	
	public bool Damage(int damage){
		bool hitSuccess=false;
		bool canDamage=true;
		
		if(health==0||character.invulnerable){
			canDamage=false;
		}
		
		if(canDamage){
			health-=damage;
			
			if(health<0){
				health=0;
			}

			character.AttackCancel();
			
			if(health>0){
				character.Hurt();
			}	else {
				character.Kill();
			}
			
			hitSuccess=true;
		}
		
		return hitSuccess;
	}
	
	public void AddHealth(int extraHealth){
		health+=extraHealth;
		
		if(health>healthMax){
			health=healthMax;	
		}
	}
}
